
/* ***********************************************************************************************
		"The Value of Urgency: Evidence from Congestion Pricing Experiments"
		Antonio M. Bento, Kevin Roth, Andrew R. Waxman
		Code: Andrew Waxman - awaxman@utexas.edu
		Last Updated: 04/06/24  			
*********************************************************************************************** 
 
************************************************************************************************/
* Expected Travel Time 30 min window

local nlist 30
forval i=1/1{
	local j: word `i' of `nlist'
	**ML data
	use ".\data\clean\MLspeeds_new5mindata", clear
	keep if inlist(hour,5,6,7,8)
	capture g dow=dow(date)
	g weekend=cond(dow==0 |dow==6,1,0)
	drop if weekend==1
	qui sum date
	local min=`r(min)'
	replace date=date-`min'
	local max=`r(max)'
	qui levelsof date, l(time)
	local first=1
	forval t=`j'/`max'{
		preserve
		qui keep if date<`t' & date>`t'-`j'
		local n=_N
		if `n'>0{
			collapse (mean) mean_speedML=speed , by(hour fwy dir)
			g date=`t'+`min'
			if `first'==1{ 
				save .\data\temp\ML_meanspeeds, replace 
				}
			else if `first'==0{ 
				append using .\data\temp\ML_meanspeeds
				qui save .\data\temp\ML_meanspeeds, replace
				}
			}
		restore
		local first=0
		di "`t' of `max'"
		}
		

	**HV
	use ".\data\clean\HV_reliab_dataset", clear
	keep if fwy==10&dir=="W"
	capture g dow=dow(date)
	g weekend=cond(dow==0 |dow==6,1,0)
	drop if weekend==1
	qui sum date
	local min=`r(min)'
	replace date=date-`min'
	local max=`r(max)'
	qui levelsof date, l(time)
	local first=1
	forval t=`j'/`max'{
		preserve
		qui keep if date<`t' & date>`t'-`j'
		local n=_N
		if `n'>0{
			collapse (mean) mean_speedEL=speed , by(hour fwy dir)
			g date=`t'+`min'
			if `first'==1{ 
				save .\data\temp\EL_meanspeeds, replace 
				}
			else if `first'==0{ 
				append using .\data\temp\EL_meanspeeds
				qui save .\data\temp\EL_meanspeeds, replace
				}
			}
		restore
		local first=0
		}
	use .\data\temp\EL_meanspeeds, clear
	merge 1:1 date hour  using .\data\temp\ML_meanspeeds, nogen 
	 g year=year(date)
	drop if year==2014
	g  month=month(date)
	g day=day(date)
	save .\data\clean\HV_ML_meanspeeds_`j'days, replace
	}
	
